package com.fit.pages;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.interfaces.*;
import com.fit.service.Jewelrys;

public class ViewJewelry {
	
	@Inject
	@Property
	private Jewelrys jewelrys;
	
	@Property
	private Jewelry currentJewelry;
	
	@InjectPage
	private JewelryDetails jewelryDetailsPage;
	
	@InjectPage
	private EntryBuy entryBuy;
	
	@OnEvent(component = "jewelryDetailsLink")
	Object onShowDetails(String jewelryName) {
		Jewelry chosenJewelry = jewelrys.retriveSingleJewelry(jewelryName);
		jewelryDetailsPage.setChosenJewelry(chosenJewelry);
		return jewelryDetailsPage;
	}
	
	@OnEvent(component = "entryBuyLink")
	Object onJewelryLink(String jewelryName) {
		entryBuy.setBuyJewelry(jewelryName);
		return entryBuy;
	}
	
	@SessionState
	private User user;

	private boolean userExists;
	
	public User getUser() {
		return user;
	}
	
	Object onActivate() {
		if (!userExists) return Login.class;
		return null;
	}
	
//	@Persist
//	private Jewelry singleJewelry;
//
//	public Jewelry getSingleJewelry() {
//		return singleJewelry;
//	}
//
//	public void setSingleJewelry(Jewelry singleJewelry) {
//		this.singleJewelry = singleJewelry;
//	}
//	
	

}
